<template>
  <t-dialog :header="`${header}【当前已勾选${selectedRowKeys.concat(selectedRowKeys2).length}】【待评审项目数${projectList.length}】`" @confirm="onSubmit"     :confirmBtn="{
        content: loading?'提交中...':'确认',
        theme: 'primary',
        loading: loading,
      }" :visible.sync="visible" :onClose="closeDialog"     :closeOnOverlayClick="false"
            width="80%" top="5%">
    <div style="height: 65vh">
    <t-table row-key="id" :columns="columns" :headerAffixedTop="{ offsetTop: 0, zIndex: 1000,container: getContainer2 }" :data="data" :selected-row-keys="selectedRowKeys"
              :loading="dataLoading"
             @select-change="(val)=>{selectedRowKeys=val}">
      <template #projectName="{row}">
        <t-link @click="dialog.objId=row.id;dialog.header=row.projectName;dialog.open_review=true" hover="color" theme="primary">{{row.projectName}}</t-link>
      </template>
      <template #op="{row}">
        <t-button  @click="dialog.header=row.projectName;dialog.objId=row.id;dialog.open_detail=true" size="small" variant="text" class="t-button-link">
          <t-icon name="info-circle" slot="icon"/>
          详情
        </t-button>
      </template>
    </t-table>
    </div>
    <special-plan-detail-dialog :header="dialog.header" :objId="dialog.objId" :visible.sync="dialog.open_detail" v-if="dialog.open_detail"></special-plan-detail-dialog>
    <file-review :header="dialog.header" achievementType="xqzjb" :visible.sync="dialog.open_review" v-if="dialog.open_review" :objId="dialog.objId"></file-review>

  </t-dialog>
</template>

<script>

import fileReview from "../../../cgzh/components/file-review.vue";
import specialPlanDetailDialog from "../../specialPlan/components/special-plan-detail-dialog.vue";

export default {
  name: "select-project",
  dicts: [],
  components:{
    fileReview,
    specialPlanDetailDialog
  },
  props: {
    header:{
      type:String,
      default:''
    },
    formData: {
      type: Object,
      default: () => ({})
    },
    projectList: {
      type: Array,
      default: ()=>[]
    }
  },
  data() {
    return {
      loading: false,
      data2: [],
      dataLoading2: false,
      selectedRowKeys2: [],
      dialog:{
        header:"",
        objId:0,
        open_detail: false,
        editOpen: true,
        open_item_detail: false,
        open_review: false,
      },
      selectedRowKeys: [],
      queryParams: {
        reviewType: '',
        pageNum: 1,
        pageSize: 10,
        dateRange: []
      },
      data:[],
      dataLoading: false,
      pagination: {
        defaultCurrent: 1,
        defaultPageSize: 10,
        total: 0,
        showPageSize: false,
        showFirstAndLastPageBtn: false,
      },
      columns: [
        {
          colKey: 'row-select',
          type: 'multiple',
          className: 'demo-multiple-select-cell',
          width: 64,
        },
        {
          colKey: "projectName",
          title: "研发需求",
          align: "center"
        },
        {
          colKey: "researchDirection",
          title: "研究方向",
          align: "center"
        },
        {
          colKey: "introducer",
          title: "提出人",
          align: "center"
        },
        {
          colKey: "deptName",
          title: "所在单位",
          align: "center"
        },
        {
          colKey: "phone",
          title: "联系电话",
          align: "center"
        },
        {
          colKey: "op",
          title: "操作",
          align: "center",
          width: 120
        },
      ],
      visible: true,
    }
  },
  watch: {
    formData: {
      immediate: true,
      handler(val) {
        if(val.id){
          this.getList();
        }
      }
    }
  },
  methods: {
    getContainer2() {
      const list = document.getElementsByClassName('t-dialog__body');
      let number = 1;
      return list[list.length - number];
    },
    getList() {
      this.dataLoading = true;
      // this.queryParams.pageNum = this.pagination.current || 1;
      this.queryParams.reviewType = this.formData.reviewType;
      this.queryParams.teamId = this.formData.id;
      this.$api.ggxq.review.teamProjectListByReviewType(this.queryParams).then((res) => {
        this.data = res.data;
        this.dataLoading = false;
      }).catch((e) => {
        this.dataLoading=false
        this.$message.error(e.toString());
      });
    },
    onSubmit(){

      if (this.selectedRowKeys.length === 0) {
        this.$message.error('请选择项目')
        return false
      }
      const businessId = this.selectedRowKeys.map(val=>({
        teamId:this.formData.id,
        businessId:val,
        reviewType: this.formData.reviewType
      }))
      this.loading = true;
      this.$api.ggxq.review.teamProjectAddList(businessId).then((res) => {
        // 初始化
        this.$message.success("选择成功");
        this.$emit("reload");
        this.$emit("update:visible", false);
        this.loading = false;
      }).catch((e) => {
        this.loading = false;
        this.$message.error(e.toString());
      });
    },
    closeDialog() {
      this.$emit("update:visible", false);
    },

  }
}
</script>

<style scoped>
.overlay-options {
  display: inline-block;
  font-size: 20px;
}
</style>
